const path = require('path')
function resolve(dir) {
    return path.join(__dirname, dir)
}

const debug = process.env.NODE_ENV !== 'production'
// const OrbitControls = require('./node_modules/three/examples/js/controls/OrbitControls')
// const AssimpJSONLoader = require('./node_modules/three/examples/js/loaders/AssimpJSONLoader.js')
// const controls = './node_modules/three/examples/js/controls'
// require.resolve("three/examples/js/controls/OrbitControls")
module.exports = {
    // 基本路径
    publicPath: './',
    // 输出文件目录
    outputDir: 'dist',
    assetsDir: 'assets',
    // eslint-loader 是否在保存的时候检查
    lintOnSave: true,
    // webpack配置
    // see https://github.com/vuejs/vue-cli/blob/dev/docs/webpack.md
    chainWebpack: config => {
        config.resolve.alias
            .set('common', resolve('src/common'))
            .set('components', resolve('src/components'))
            .set('api', resolve('src/api'))
            .set('assets', resolve('src/assets'))
            .set('utils', resolve('src/utils'))
            .set('psvJs', resolve('src/psvJs'))
            .set('gaodeJs', resolve('src/gaodeJs'))
        // .set('threejs', path.resolve(__dirname, threejs))
        config.externals({
            // 'Ammo': 'Ammo',
            'PhotoSphereViewer': 'PhotoSphereViewer'
        })
        config.module
            .rule('imports-loader')
            .test(/\.mtl$|\.obj$/)
            .use('file')
            .loader('file-loader')
            .end()
        config.module
            .rule('imports-loader')
            .test(/three\/examples\/js/)
            .use('imports-loader?THREE=three')
            .loader('imports-loader?THREE=three')
            .end()
        // config.module
        //     .rule('imports-loader')
        //     .test(require.resolve('three/examples/js/effects/StereoEffect'))
        //     .use('imports-loader?THREE=three')
        //     .loader('imports-loader?THREE=three')
        //     .end()
        // config.module
        //     .rule('exports-loader')
        //     .test(OrbitControls)
        //     .use('exports-loader?THREE.OrbitControls')
        //     .loader('exports-loader?THREE.OrbitControls')
        //     .end()
    },
    configureWebpack: (config) => {
        if (debug) { // 开发环境配置
            config.devtool = 'eval-source-map'
        } else { // 生产环境配置
        }
        // Object.assign(config, { // 开发生产共同配置
        //     resolve: {
        //         alias: {
        //             '@': path.resolve(__dirname, './src'),
        //             '@c': path.resolve(__dirname, './src/components'),
        //             'vue$': 'vue/dist/vue.esm.js'
        //         }
        //     }
        // })
    },
    // 生产环境是否生成 sourceMap 文件
    productionSourceMap: false,

    // css相关配置
    css: {
        // 是否使用css分离插件 ExtractTextPlugin
        extract: true,
        // 开启 CSS source maps?
        sourceMap: false,
        // css预设器配置项
        loaderOptions: {},
        // 启用 CSS modules for all css / pre-processor files.
        modules: false
    },
    // use thread-loader for babel & TS in production build
    // enabled by default if the machine has more than 1 cores
    parallel: require('os').cpus().length > 1,
    // webpack-dev-server 相关配置
    devServer: {
        open: process.platform === 'darwin',
        host: '0.0.0.0',
        port: 8080,
        https: false,
        hotOnly: false,
        proxy: {
            '/Data': {
                target: 'http://localhost:8084', // 接口的域名
                // secure: false,  // 如果是https接口，需要配置这个参数
                changeOrigin: true, // 如果接口跨域，需要进行这个参数配置
                pathRewrite: {
                    '^/Data': '/'
                }
            },
            '/data': {
                target: 'http://localhost:8888/', // 接口的域名
                // secure: false,  // 如果是https接口，需要配置这个参数
                changeOrigin: true, // 如果接口跨域，需要进行这个参数配置
                pathRewrite: {
                    '^/data': '/'
                }
            }
        },
        before: app => { }
    },
    // 第三方插件配置
    pluginOptions: {
        // ...
    }
}